﻿using PLCS.Application.Contracts.HisTaskApp.Dtos;
using PLCS.Client.IService.OrderTask;
using System.Collections.ObjectModel;
using Volo.Abp.Application.Dtos;

namespace PLCS.Client.Service.OrderTask;

public class HisTaskService : BaseService<HisTaskDto, HisTaskDto>, IHisTaskService
{
    public async Task AgainIssuedAsync(HisTaskDto hisTask)
    {
        RequestParam requestParam = new RequestParam(Method.Post, $"hisTask/againIssued", hisTask);
        await restClient.ExecuteAsync(requestParam);
    }

    public async Task<PagedResultDto<HisTaskDto>> GetListBySearchAsync(int skipCount, int maxResultCount, string? taskId, string? startTime, string? endTime)
    {
        var route = $"hisTask/bySearch?SkipCount={skipCount}&MaxResultCount={maxResultCount}";
        if (!string.IsNullOrEmpty(taskId))
            route = route + $"&taskNo={taskId}";
        if (!string.IsNullOrEmpty(startTime))
            route += $"&startTime={startTime}";
        if (!string.IsNullOrEmpty(endTime))
            route += $"&endTime={endTime}";
        RequestParam requestParam = new(method: Method.Get, route: route);
        var apiRes = await restClient.ExecuteAsync<PagedResultDto<HisTaskDto>>(requestParam);
        if (apiRes.Status)
            return apiRes.Data;
        else
            return new PagedResultDto<HisTaskDto>();
    }
}